using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class DLXMRayBallController : MonoBehaviour
{


    private SpriteRenderer sprite;
    private Rigidbody2D rigidby;
    private Vector4 spriteColor;
    private Vector3 scale;
    private Vector3 minScale;

    public float scaleSpeed;
    public float alphaSpeed;
    public float startMoveSpeed;
    public float shotSpeed;
    public float dispareTime;

    void Start()
    {
        sprite = GetComponent<SpriteRenderer>();
        rigidby = GetComponent<Rigidbody2D>();
        scale = transform.localScale;
        minScale = scale * 0.25f;
        spriteColor = sprite.color;
        spriteColor.w = 0;
        sprite.color = spriteColor;
        rigidby.velocity = new Vector2(0, -startMoveSpeed);
    }

    private void Update()
    {
        spriteColor.w += alphaSpeed;
        sprite.color = spriteColor;
        scale.x-= scaleSpeed;
        scale.y-= scaleSpeed;
        if(scale.x > minScale.x || scale.y > minScale.y)
        transform.localScale = scale;

    }
    public void shot(int scaleX)
    {
        rigidby.velocity = new Vector2(scaleX * shotSpeed, 0);
        Invoke("Distory", dispareTime);
    }
   
    public void Distory()
    {
        Destroy(gameObject);
    }
}
